#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    int n = 0, k = 0;
    cin >> n >> k;
    vector<int> a(n, 0);
    for (int i = 0;i < n;i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int l = 0, r = 0;
    int max = 0;
    while (r < a.size())
    {
        if (abs(a[l] - a[r]) <= k)
        {
            ++r;
        }
        else
        {
            if (r - l > max) max = r - l;
            ++l;
        }
    }
    if (r - l > max) max = r - l;
    cout << max << endl;
    return 0;
}